<h2> Liste des factures</h2>

<table id="t_facture" >
	<thead>
    	<tr>
    		<th> ID </th>
            <th> Client </th>
            <th> Date </th>
            <th> Echeance </th>
            <th> Montant TTC </th>
    		<th></th>
    	</tr>
    </thead>
	<?foreach($factures as $facture){
		$client = $aContacts[$facture->contact_id];
		$client_name = $client->prenom." ".$client->nom;
		if($client->societe != "")
			$client_name .= " (".$client->societe.")";
	?>
        <tr>
        	<td><?=$facture->_id?></td>
            <td><?=$client_name?></td>
            <td><?=date("d-m-Y",strtotime($facture->date))?>
					 <a href="javascript:changeDate('<?=$facture->_id?>');"><img src="/public/images/icons/date.png" title="Changer la date de la facture"/></A>
            </td>
            <td><?=date("d-m-Y",strtotime($facture->echeance))?> 
					 <a href="javascript:changeEcheance('<?=$facture->_id?>');"><img src="/public/images/icons/date.png" title="Changer la date d'échéance"/></A></td>
            <td><?=$facture->montant_ttc?> &euro;</td>
            <td> 
            	<a href="/ventes/facture/download/<?=$facture->_id?>" target="_blank"><img src="/public/images/icons/pdf.png" title="Télécharger la facture"/></a>
            	<?if(!isset($aPaiementsClient[$facture->_id])){?>
            		<a href="javascript:removeFacture('<?=$facture->_id?>');"><img src="/public/images/icons/remove.png" title="Supprimer la facture"/></a>
            		<a href="javascript:enregistrerPaiement('<?=$facture->_id?>');"><img src="/public/images/icons/dollar.png" title="Enregistrer le paiement"/></a>
            	<?}else{?>
            		
            	<?}?> 
            	<a href="javascript:previewFacture('<?=$facture->_id?>');"><img src="/public/images/icons/preview.png" title="Apreçu"/></a>
            </td>
    	</tr>
	<?}?>
</table>
<div id="changeEcheance_dial" title="Changer la date d'échéance de la facture"> 
	 <form id="changerEcheance_form">
		  <input type="hidden" name="facture_id" id="echeance_factureid"/>
		  <div class="datepicker" id="new_echeance" style="margin-left:20px;margin-top:20px;"></div>
		  <input type="hidden" name="echeance"/>
	 </form>
</div>
<div id="changeDate_dial" title="Changer la date de la facture"> 
	 <form id="changerDate_form">
		  <input type="hidden" name="facture_id" id="date_factureid"/>
		  <div class="datepicker" id="new_date" style="margin-left:20px;margin-top:20px;"></div>
		  <input type="hidden" name="date"/>
	 </form>
</div>